import {
	db
} from '@/common/config.js'
import {
	usqlite
} from '@/uni_modules/onemue-USQLite/js_sdk/usqlite.js'
 
uni.$sql = usqlite;


const files = require.context("./data", false, /\.js$/);


const Model = async (name, callback) => { 
	let model = await new Promise(resolve => {
		uni.$sql.connect(db, e => {
			console.log(e)
			files.keys().forEach((key) => {
				if (files(key).default.name == name) {
					let model = uni.$sql.model(files(key).default.name, files(key).default.field);
					resolve(model);
				}
			});
		});
	})
	callback(model)
}


export default Model